*SM-E22-Figure

set scheme stcolor
version 17
use ../Metadata/tess_analysisdata.dta, clear


* % hypotheses supported 
	tempvar temp
	cap drop total_hyp_true
	
	egen total_hyp_true=sum(hyp_true_insample), by(vendor_id)
	gen `temp'=  total_hyp_true/total_hyp_insample
	egen pctsupported= max(`temp'), by(vendor_id)
	

********************************************************************************

* median sample size per category
preserve
keep if hyp_num==1
egen samplesizecatmed=median(samplesize), by(samplesizecat)
tab samplesizecat samplesizecatmed
restore

* create frame
cap frame change default
cap frame drop results
frame create results strL varname mean se ul ll str8 N


* Sample size, study level

	* study level analysis
	keep if hyp_num==1

	mean pctsupported if samplesize<=1000, level(83.4)
	mat table = r(table)	
	local mean = table[1,1]
	local se = table[2,1]
	local ll = table[5,1]
	local ul = table[6,1]
	local N	 = table[7,1]+1		
	frame post results ("1000 or less") (`mean') (`se') (`ll') (`ul') ("N=`N'")
		
	mean pctsupported  if samplesize>=1001 & samplesize<=2000, level(83.4)		
	mat table = r(table)	
	local mean = table[1,1]
	local se = table[2,1]
	local ll = table[5,1]
	local ul = table[6,1]
	local N	 = table[7,1]+1		
	frame post results ("1001-2000") (`mean') (`se') (`ll') (`ul') ("N=`N'")

	mean pctsupported  if samplesize>=2001 & samplesize<=3000, level(83.4)		
	mat table = r(table)	
	local mean = table[1,1]
	local se = table[2,1]
	local ll = table[5,1]
	local ul = table[6,1]
	local N	 = table[7,1]+1		
	frame post results ("2001-3000") (`mean') (`se') (`ll') (`ul') ("N=`N'")
	
	mean pctsupported  if samplesize>=3001, level(83.4)	
	mat table = r(table)	
	local mean = table[1,1]
	local se = table[2,1]
	local ll = table[5,1]
	local ul = table[6,1]
	local N	 = table[7,1]+1		
	frame post results ("Over 3001") (`mean') (`se') (`ll') (`ul') ("N=`N'")	
			

	
* graph

frame change results
gen xlabel=_n
labmask xlabel, values(varname)
gen mlabel=0.1

		graph twoway ///
		(bar mean xlabel if xlabel<=4, barw(0.8) fc(stc2%50) colordiscrete lc(none)) || ///
		(rcap ll ul xlabel if xlabel<=4,lc(gs7)) ///
		(scatter mlabel xlabel if _n<=4, ///		
msym(none) mlab(N) mlabpos(6) mlabcolor(black) mlabsize(3.4) mlabangle(hor)) ///
		, ///	
			ytitle("Prop. of supported hypotheses", size(3.8) margin(r=0 l=-4)) ///
			xlabel( ///
			, labsize(3.5) angle(ver) valuelabels) ///
			xtitle("Study sample size", margin(b=0) size(3.8)) ///
			ylabel(0(0.2)1, labsize(3.8) nogrid) ///
			scheme(s2mono) ///
			graphregion(color(white)) ///
			legend(off) ///
			name(study, replace)
	

	graph export "../Results/E22-SamplesizeSuccess.pdf", replace	

	